package com.lanou3g.k12.service.impl;

import com.lanou3g.k12.entity.Chapter;
import com.lanou3g.k12.mapper.ChapterMapper;
import com.lanou3g.k12.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ChapterServiceImpl implements ChapterService {
    @Autowired
    private ChapterMapper chapterMapper;
    @Override
    public List<Chapter> search(String searchText) {
        List<Chapter> byKeyword = chapterMapper.findByKeyword("%" + searchText + "%");
        return byKeyword;
    }

    @Override
    public List<Chapter> findAll(Long cid) {
        List<Chapter> all = chapterMapper.findAll(cid);
        return all;
    }

    @Override
    public void delete(Long[] ids) {
        chapterMapper.deleteByIds(ids);
    }

    @Override
    public void insert(Chapter chapter) {
        Date date = new Date();
        chapter.setCreateTime(date);
        chapter.setUpdateTime(date);
        chapterMapper.insert(chapter);
    }

    @Override
    public void update(Long id, Chapter chapter) {
        Date date = new Date();
        chapter.setUpdateTime(date);
        chapterMapper.updateById(id,chapter);
    }

    @Override
    public void deleteById(Long id) {
        chapterMapper.deleteById(id);
    }
}
